package com.cuiyun97.mapper;

import com.cuiyun97.enumeration.OperationType;
import com.cuiyun97.annotation.AutoFillField;
import com.cuiyun97.domain.dto.AdminPageQueryDTO;
import com.cuiyun97.domain.po.Admin;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AdminMapper {

    /**
     * 分页查询
     *
     * @param adminPageQueryDTO
     * @return
     */
    Page<Admin> pageQuery(AdminPageQueryDTO adminPageQueryDTO);

    /**
     * 登录
     *
     * @param username
     * @return
     */
    @Select("select * from admin where username = #{username}")
    Admin getByUsername(String username);

    /**
     * 新增
     *
     * @param admin
     */
    @Insert("insert into admin(username, password, name, avatar, mobile, create_time, update_time, create_user, " +
            "update_user, status, sort, deleted, is_cyzz) value(#{username}, #{password}, #{name}, #{avatar}, " +
            "#{mobile}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser}, " +
            "#{status}, #{sort}, #{deleted}, #{isCyzz})")
    @AutoFillField(value = OperationType.INSERT)
    void insert(Admin admin);

    /**
     * 更新
     *
     * @param admin
     */
    @AutoFillField(value = OperationType.UPDATE)
    void update(Admin admin);

    /**
     * 根据ID查询
     *
     * @param id
     * @return
     */
    @Select("select * from admin where id = #{id}")
    Admin getById(Integer id);

    /**
     * 批量删除
     *
     * @param ids
     */
    void delete(List<Integer> ids);
}
